<div class="window times">
	<div class="title">Time reports</div>
	<div class="content">
		<table style="width: 100%;">
			<tr class="header">
				<td>Comment</td>
				<td>Username</td>
				<td>Report</td>
				<td>Pause</td>
				<td>Date</td>
				<?php if ($current_user['User']['role'] != 'spectator') : ?>
				<td>Actions</td>
				<?php endif; ?>
			</tr>
			<?php foreach($times as $i => $time) : ?>
			<tr>
				<td class="comment <?php echo ($i % 2 ==0 ) ? 'not-even' : 'even'; ?>"><?php 
					if (empty($time['Time']['comment']))
					{
						echo '-';
					}
					else
					{
						echo $time['Time']['comment'];
					}
				?></td>
				<td class="username <?php echo ($i % 2 ==0 ) ? 'not-even' : 'even'; ?>"><?php echo $time['User']['username']; ?></td>
				<td class="report <?php echo ($i % 2 ==0 ) ? 'not-even' : 'even'; ?>">
					<?php echo $date->minutesToTime($time['Time']['finish'] - $time['Time']['start'] - $time['Time']['pause']); ?>
				</td>
				<td class="pause <?php echo ($i % 2 ==0 ) ? 'not-even' : 'even'; ?>">
					<?php echo $date->minutesToTime($time['Time']['pause']); ?>
				</td>
				<td class="date <?php echo ($i % 2 ==0 ) ? 'not-even' : 'even'; ?>">
					<?php echo $date->minutesToDate($time['Time']['finish']); ?>
				</td>
				<?php if ($current_user['User']['role'] != 'spectator') : ?>
				<td class="actions <?php echo ($i % 2 ==0 ) ? 'not-even' : 'even'; ?>">
					<?php if($current_user['User']['id'] == $time['Time']['user_id']) : ?>
						<?php echo $html->link('edit', array('controller' => 'times', 'action' => 'report', $time['Time']['id'])); ?>
					<?php endif; ?>
				</td>
				<?php endif; ?>
			</tr>
			<?php endforeach; ?>
		</table>
	</div>
</div>
<div class="window task">
	<div class="title">View task</div>
	<div class="content">
		<div class="task-item">
			<div><i><?php echo $task['Creator']['username']; ?> post to <?php echo $task['Task']['created']; ?></i></div>
			<h1><?php echo $task['Task']['name']; ?></h1>
			<div><?php echo $task['Task']['desc']; ?></div>
			<?php echo $this->element('attach_files', array('media' => $task['Media'])); ?>
		</div>
		<?php echo $this->element('comments'); ?>
	</div>
</div>
<?php if ($current_user['User']['role'] != 'spectator') : ?>
<div class="window task-update">
	<div class="title">Task update</div>
	<div class="content">
		<?php echo $form->create('Task', array('url' => '/tasks/update')); ?>
		<?php echo $form->input('id', array('type' => 'hidden', 'value' => $task['Task']['id'])); ?>
		<?php if ($task['Task']['status'] != 'closed') : ?>
		<div>
			<input type="radio" id="CloseOption" name="data[Task][status]" value="closed"/>
			<label for="CloseOption">Close</label>
		</div>
		<?php endif; ?>
		<?php if ($task['Task']['status'] == 'closed') : ?>
		<div>
			<input type="radio" id="ReopenOption" name="data[Task][status]" value="reopened"/>
			<label for="ReopenOption">Open</label>
		</div>
		<?php endif; ?>
		<div>
			<input type="radio" <?php if (empty($users)) {echo 'disabled="disabled"';} ?> id="ReassignOption" name="data[Task][status]" value="reassigned"/>
			<label for="ReassignOption">Reassign to</label>
			<?php echo $form->input('performer_id', array('label' => false, 'div' => false ,'options' => $users, 'disabled' => empty($users))) ?>
		</div>
		<?php if ($task['Task']['status'] != 'closed') : ?>
		<div>
			<label style="float:left; padding: 0 4px 0 26px; width: 78px; text-align: left;">Priority</label>
			<?php echo $form->input('priority', array('label' => false, 'div' => false ,'options' => array(1 => 'low', 2 => 'medium', 3 => 'high'), 'default' => $task['Task']['priority'])) ?>
		</div>
		<?php endif; ?>
		<?php echo $form->input('comment', array('type' => 'textarea', 'style' => 'max-width: 257px; min-width: 257px;')); ?>
		<?php echo $form->end('Submit'); ?>
	</div>
</div>
<?php endif; ?>
<script>
	$(".attach-file a").click(function(){
		window.open($(this).attr("href"),'Download');
		console.log($(this).attr("href"));
		return false;
	});
</script>
<script>
	$("#attach-another-file a").click(function(){
		
		$("div.files").append("<div class=\"file\"><input type=\"file\" name=\"data[Files][]\" /></div>");
		
		return false;
	});
</script>